import {get} from '../utils/http';
import {
    urlFormat,
    API_COURESE_LIST,
    API_GET_COURSE_LESSONS,
    API_GET_LESSON,
    API_GET_COURSE_INFO,
    API_GET_COURSE_CATALOG,
    API_GET_COURSE_INTRO
} from '../common/constants';

exports.getCoureseList = (tagId, nextId, count = 10) => {
    let params = {};

    if (tagId) {
        params.tagId = tagId;
    }
    if (nextId) {
        params.nextId = nextId;
    } else {
        params.nextId = '';
    }
    params.count = count;
    return get(API_COURESE_LIST, params);
};

exports.getCourseLessons = (courseId) => {
    let path = API_GET_COURSE_LESSONS + '/' + courseId;
    return get(path);
};

exports.getCourseInfo = (courseId) => {
    let path = urlFormat(API_GET_COURSE_INFO, {
        courseId
    });
    return get(path);
};

exports.getCourseCatalog = (courseId) => {
    let path = urlFormat(API_GET_COURSE_CATALOG, {
        courseId
    });
    return get(path);
};

exports.getCourseIntro = (courseId) => {
    let path = urlFormat(API_GET_COURSE_INTRO, {
        courseId
    });
    return get(path);
};

exports.getLessonDetail = (lessonId) => {
    return get(urlFormat(API_GET_LESSON, {lessonId: lessonId}));
};
